package com.lc.cms.contoller;

import com.lc.cms.dto.CreateRoleDto;
import com.lc.cms.dto.RolePermissionDto;
import com.lc.cms.model.RoleModel;
import com.lc.cms.service.IRoleService;
import com.lc.cms.utils.ResponseResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("role")
@Log4j2
public class RoleController {

    private final IRoleService roleService;

    @Autowired
    public RoleController(IRoleService roleService) {
        this.roleService = roleService;
    }

    @RequestMapping("create")
    public ResponseResult create(CreateRoleDto role) {
        Long start = new Date().getTime();
        ResponseResult responseResult = roleService.create(role);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("update")
    public ResponseResult update(RoleModel role) {
        Long start = new Date().getTime();
        ResponseResult responseResult = roleService.update(role);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("delete")
    public ResponseResult delete(int id) {
        Long start = new Date().getTime();
        ResponseResult responseResult = roleService.delete(id);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("updateRolePermission")
    public ResponseResult createRolePermission(RolePermissionDto role) {
        Long start = new Date().getTime();
        ResponseResult responseResult = roleService.updateRolePermission(role);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }
}
